import axios from 'axios'

let onquest = axios.create({
  baseURL: '/api/',
  transformRequest: [function (data) {
    return data
  }],
  transformResponse: [function (data) {
    let res = data.match(/(^artiList\()([\d\D]*)(\)$)/)
    return JSON.parse(res[2])
  }]
})

const $http = (url, data) => {
  return new Promise(resolve => {
    let promise = onquest(url, { data })
    promise.then(res => {
      resolve(res.data)
    }).catch(err => {
      console.log('reject', err)
    })
  })
}

export default $http
